package com.ktgj.flight.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.ktgj.flight.domain.FlightOrderInfo;
import com.ktgj.flight.domain.vo.FinanceConsignPymtLogVo;
import com.ktgj.flight.mapper.FlightOrderInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.flight.mapper.FinanceConsignPymtLogMapper;
import com.ktgj.flight.domain.FinanceConsignPymtLog;
import com.ktgj.flight.service.IFinanceConsignPymtLogService;

/**
 * 财务机票代收交易日志Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-06-15
 */
@Service
public class FinanceConsignPymtLogServiceImpl implements IFinanceConsignPymtLogService 
{
    @Autowired
    private FinanceConsignPymtLogMapper financeConsignPymtLogMapper;
    @Autowired
    private FlightOrderInfoMapper flightOrderInfoMapper;

    /**
     * 查询财务机票代收交易日志
     * 
     * @param financeConsignPymtLogId 财务机票代收交易日志ID
     * @return 财务机票代收交易日志
     */
    @Override
    public FinanceConsignPymtLog selectFinanceConsignPymtLogById(Long financeConsignPymtLogId)
    {
        return financeConsignPymtLogMapper.selectFinanceConsignPymtLogById(financeConsignPymtLogId);
    }

    /**
     * 查询财务机票代收交易日志列表
     * 
     * @param financeConsignPymtLog 财务机票代收交易日志
     * @return 财务机票代收交易日志
     */
    @Override
    public List<FinanceConsignPymtLog> selectFinanceConsignPymtLogList(FinanceConsignPymtLog financeConsignPymtLog)
    {
        return financeConsignPymtLogMapper.selectFinanceConsignPymtLogList(financeConsignPymtLog);
    }

    /**
     * 新增财务机票代收交易日志
     * 
     * @param financeConsignPymtLog 财务机票代收交易日志
     * @return 结果
     */
    @Override
    public int insertFinanceConsignPymtLog(FinanceConsignPymtLog financeConsignPymtLog)
    {
        return financeConsignPymtLogMapper.insertFinanceConsignPymtLog(financeConsignPymtLog);
    }

    /**
     * 修改财务机票代收交易日志
     * 
     * @param financeConsignPymtLog 财务机票代收交易日志
     * @return 结果
     */
    @Override
    public int updateFinanceConsignPymtLog(FinanceConsignPymtLog financeConsignPymtLog)
    {
        return financeConsignPymtLogMapper.updateFinanceConsignPymtLog(financeConsignPymtLog);
    }

    /**
     * 批量删除财务机票代收交易日志
     * 
     * @param financeConsignPymtLogIds 需要删除的财务机票代收交易日志ID
     * @return 结果
     */
    @Override
    public int deleteFinanceConsignPymtLogByIds(Long[] financeConsignPymtLogIds)
    {
        return financeConsignPymtLogMapper.deleteFinanceConsignPymtLogByIds(financeConsignPymtLogIds);
    }

    /**
     * 删除财务机票代收交易日志信息
     * 
     * @param financeConsignPymtLogId 财务机票代收交易日志ID
     * @return 结果
     */
    @Override
    public int deleteFinanceConsignPymtLogById(Long financeConsignPymtLogId)
    {
        return financeConsignPymtLogMapper.deleteFinanceConsignPymtLogById(financeConsignPymtLogId);
    }

    /**
     * 支付记录录入
     * */
    @Override
    public int saveFinanceConsignPymtLog(FinanceConsignPymtLogVo financeConsignPymtLogVo) {
        FlightOrderInfo flightOrderInfo = new FlightOrderInfo();
        flightOrderInfo.setOrderId(Long.valueOf(financeConsignPymtLogVo.getOrderNum()));
        flightOrderInfo.setPayType(financeConsignPymtLogVo.getCollectionChannel());
        flightOrderInfo.setPayAmount(new BigDecimal(financeConsignPymtLogVo.getAmount()));
        flightOrderInfo.setBillNo(financeConsignPymtLogVo.getTransactionSerialNumber());
        if (flightOrderInfo.getGuestMemo() != null){
            flightOrderInfo.setGuestMemo(flightOrderInfo.getGuestMemo() + " " + financeConsignPymtLogVo.getRemark());
        }
        else {
            flightOrderInfo.setGuestMemo(financeConsignPymtLogVo.getRemark());
        }

        int i = flightOrderInfoMapper.updateFlightOrderInfo(flightOrderInfo);
        return i;
    }
}
